﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;

namespace GlxRRSReporter.Utils
{
    public class ExportToExcel
    {
        static Excel.Application myExcelApp = new Excel.Application();
        static bool isInit = false;
        public static Excel.Workbook openExcelWorkbooks(string fileName)
        {
            Excel.Workbooks myExcelWorkbooks;
            object misValue = System.Reflection.Missing.Value;
            //
            myExcelApp.Visible = true;
            myExcelWorkbooks = myExcelApp.Workbooks;

            Excel.Workbook myExcelWorkbook = myExcelWorkbooks.Open(fileName, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
            //
            isInit = true;
            return myExcelWorkbook;
        }
        public static void quitExcel()
        {
            if (isInit)
                myExcelApp.Quit();
        }
    }
}
